﻿using CMS.Enbities;
using CMS.Models;
using CMS.ViewModel;
using Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CMS.View
{
    /// <summary>
    /// CargoView.xaml 的交互逻辑
    /// </summary>
    public partial class CargoView : UserControl
    {
        public CargoView()
        {
            InitializeComponent();
            Loaded += (s, e) =>
            {
                var vm = DataContext as CargoViewModel;
                vm.Cargos = new CargoProvider().Select();
                vm.CargoTypes = new CargoTypeProvider().Select();
                vm.UnitTypes = new UnitTypeProvider().Select();

                var records = new RecordProvider().Select();
                //遍历这个类
                vm.Cargos.ForEach(cargo =>
                {
                    var list = records.FindAll(item => item.CargoId == cargo.Id);
                    if (list != null)
                    {
                        //统计
                        var inputCount = list.FindAll(item => item.RecoredType == true).Sum(item => item.Number);
                        var outputCount = list.FindAll(item => item.RecoredType == false).Sum(item => item.Number);
                        var sumCount = inputCount - outputCount;
                        cargo.Sum = sumCount;
                    }

                });
            };
        }
    }
}
